package software.project;

import android.graphics.Bitmap;
import android.util.DisplayMetrics;
import android.util.Log;

public class Spider {
	
	private Bitmap SpiderBMP;
	private int posX;
	private int posY;
	private static final float size = 0.05f;

	public Spider(Bitmap bmp, DisplayMetrics metrics){
		SpiderBMP = bmp;
		float mXDpi = metrics.xdpi;
	    float mYDpi = metrics.ydpi;
	    float mMetersToPixelsX = mXDpi / 0.0254f;
	    float mMetersToPixelsY = mYDpi / 0.0254f;
	    final int dstWidth = (int) (size * mMetersToPixelsX + 0.6f);
        final int dstHeight = (int) (size * mMetersToPixelsY + 0.6f);
        posX= 20;
        posY= 300;
		Bitmap.createScaledBitmap(SpiderBMP, dstWidth, dstHeight, true);
	}
	
	public int getPosX(){
		return this.posX;
	}
	
	public int getPosY(){
		return this.posY;
	}
	
	public Bitmap getBitmap(){
		return SpiderBMP;
	}
	
	public void UpdatePositions(DisplayMetrics metrics){
		int Mov = (int) (Math.random()*4)+1;
		int dif= 3;
		int height = metrics.heightPixels;
		int width  = metrics.widthPixels;
		
		float widthBMP = (float) (SpiderBMP.getWidth()*.85);
		float heightBMP= (float) (SpiderBMP.getHeight()*.9);
		
		switch (Mov) { 
			case 1:	if(posX-dif>0)											//Izquierda
						posX-=dif;
					break;
					
			case 2: if(posY-dif>0)											//Arriba
						posY-=dif;
					break;	
					
			case 3: if(posX+dif+widthBMP<width)								//Derecha
						posX+=dif;
					break;
					
			case 4: if((posY+dif+heightBMP)<height)								//Abajo
						posY+=dif;
					break;
					
			case 5: if(posX-dif>0 && posY-dif<0){							//Izquierda Superior
						posY-=dif;	
						posX-=dif;
					}
					break;
					
			case 6: if((posX+dif+widthBMP)<width && posY-dif<0){				//Derecha Superior
						posY-=dif;
						posX+=dif;
					}
					break;
					
			case 7: if(posX-dif>0 && (posY+dif+heightBMP)<height){					//Izquierda Inferior
						posY+=dif;
						posX-=dif;
					}
					break;
					
			case 8: if((posX+dif+widthBMP)<width && (posY+dif+heightBMP)<height){		//Derecha Inferior
						posY+=dif;
						posX+=dif;
					}
					break;
			default:
		}
	}
}